package com.suhuamo.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        List<Integer> numbers = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            numbers.add(i);
        }

        Stream<Integer> integerStream = numbers.stream().filter(e -> !e.equals(-1));

        // 这三个输出无论放开哪个都会报错 stream has already been operated upon or closed
        //System.out.println("integerStream.count() = " + integerStream.count());
        for (int i = 0; i < 9; i++) {
            numbers.remove(0);
        }
        //System.out.println("integerStream.count() = " + integerStream.count());
        //integerStream.forEach(System.out::println);
        //System.out.println("integerStream.count() = " + integerStream.count());
        System.out.println("stream");
        List<Integer> collect = integerStream.collect(Collectors.toList());
        numbers.add(3);
        numbers.add(0,1);
        System.out.println("numbers = " + numbers);
        System.out.println("collect = " + collect);

        List<Student> students = new ArrayList<>();
        students.add(new Student("张三", 18));
        students.add(new Student("张四", 12));
        List<Student> collect1 = students.stream().collect(Collectors.toList());
        students.get(0).name = "还好";
        System.out.println("students = " + students);
        System.out.println("collect1 = " + collect1);
    }
}
